package com.crm.repository;

import com.crm.entity.Student;

import java.util.List;
import java.util.Optional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;


public interface StudentRepositoy  extends JpaRepository<Student,String>, JpaSpecificationExecutor<Student> {

	/**
     * 根据id查询信息 。供excel导出用
     * @param id
     * @return
     */
    @Query(nativeQuery = true,value = "select * from student where stuid=?1")
    Optional<Student> findByExcelId(String id);
    
  //根据网络咨询师id查出下面的学生
  	@Query(value="select * from student where net_asker_id=?1",nativeQuery=true)
  	List<Student> Cha(Integer netAskerId);
  	//给咨询师分配学生(相当于已存在的学生加上咨询师id就行 所以这里是一个修改方法)
  	@Modifying
  	@Query(value=" update student set asker_id=?2 where stuid=?1",nativeQuery=true)
  	Integer FenPeiStu(String Stuid,Integer askerId);
}
